﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using log4net;
using System.Reflection;
using Util;
using System.IO;

namespace WebCollection
{
    class Dir
    {
        private static ILog log = log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);

        public string root;

        public Dir(string root)
        {
            if (!Directory.Exists(root))
            {
                Directory.CreateDirectory(root);
            }
            this.root = root;
        }

        public string GetFileName(string url)
        {
            string relative = UrlUtil.FormatUrlToFileName(url);
            string absolute = Path.Combine(root, relative);

            if (absolute.Length >= 5000)
            {
                System.Guid guid = new Guid();
                guid = Guid.NewGuid();
                string str = guid.ToString();
                string fn= str + ".xml";
                return fn;
            }

            string filename= absolute + ".xml";
            return filename;
        }
    }
}
